package com.woniu.his.bms.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.his.bms.client.BmsOperatorSettleRecordClient;
import com.woniu.his.bms.client.param.OperatorSettleRecordByTimeAndStaffParam;
import com.woniu.his.bms.client.param.QueryOperatorSettleRecordByTimeAndStaffIdParam;
import com.woniu.his.bms.client.param.VerifyForSettleRecordParam;
import com.woniu.his.bms.client.result.OperatorSettleRecordResult;
import com.woniu.his.bms.service.OperatorSettleRecordService;
import com.woniu.his.bms.service.dto.OperatorSettleRecordDto;
import com.woniu.his.bms.service.param.OperatorSettleRecordByTimeAndStaffServiceParam;
import com.woniu.his.bms.service.param.QueryOperatorSettleRecordByTimeAndStaffIdServiceParam;
import com.woniu.his.bms.service.param.VerifyForSettleRecordServiceParam;
import com.woniu.his.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@RestController
@Slf4j
@RequestMapping("/bms")
public class BmsOperatorSettleRecordApiImpl implements BmsOperatorSettleRecordClient {

    @Resource
    private OperatorSettleRecordService operatorSettleRecordService;

    @Override
    public Result operatorSettleRecordByTimeAndStaff(Long staffId) {

        log.info("日结传回来的参数：{}",staffId);
        operatorSettleRecordService.operatorSettleRecordByTimeAndStaff(staffId);
        return Result.getInstance();
    }

    @Override
    public Result<OperatorSettleRecordResult> queryOperatorSettleRecordById(Long id) {

        log.info("查日结传回来的ID：{}",id);
        OperatorSettleRecordDto result=operatorSettleRecordService.queryOperatorSettleRecordById(id);
        OperatorSettleRecordResult recordResult=BeanUtil.copyProperties(result,OperatorSettleRecordResult.class);
        return Result.getInstance(OperatorSettleRecordResult.class).setData(recordResult);
    }

    @Override
    public Result verifyForSettleRecord(VerifyForSettleRecordParam param) {

        log.info("对账所传的参数：{}",param);
        VerifyForSettleRecordServiceParam serviceParam=BeanUtil.copyProperties(param,VerifyForSettleRecordServiceParam.class);
        operatorSettleRecordService.verifyForSettleRecord(serviceParam);
        return Result.getInstance();
    }

    @Override
    public Result<List<OperatorSettleRecordResult>> queryOperatorSettleRecordByTimeAndStaffId(@Valid QueryOperatorSettleRecordByTimeAndStaffIdParam param) {

        log.info("查日结，传回来的参数：{}",param);
        QueryOperatorSettleRecordByTimeAndStaffIdServiceParam serviceParam=BeanUtil.copyProperties(param, QueryOperatorSettleRecordByTimeAndStaffIdServiceParam.class);
        List<OperatorSettleRecordDto> list=operatorSettleRecordService.queryOperatorSettleRecordByTimeAndStaffId(serviceParam);
        List<OperatorSettleRecordResult> results=BeanUtil.copyToList(list,OperatorSettleRecordResult.class);
        return Result.getInstanceList(OperatorSettleRecordResult.class).setData(results);
    }
}
